package com.dmcliver.timetracker.session;

import com.dmcliver.timetracker.entity.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("timeentryHome")
public class TimeentryHome extends EntityHome<Timeentry> {

	@In(create = true)
	JobHome jobHome;
	@In(create = true)
	PersonHome personHome;

	public void setTimeentryTimeentryid(BigDecimal id) {
		setId(id);
	}

	public BigDecimal getTimeentryTimeentryid() {
		return (BigDecimal) getId();
	}

	@Override
	protected Timeentry createInstance() {
		Timeentry timeentry = new Timeentry();
		return timeentry;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		Job job = jobHome.getDefinedInstance();
		if (job != null) {
			getInstance().setJob(job);
		}
		Person person = personHome.getDefinedInstance();
		if (person != null) {
			getInstance().setPerson(person);
		}
	}

	public boolean isWired() {
		if (getInstance().getJob() == null)
			return false;
		if (getInstance().getPerson() == null)
			return false;
		return true;
	}

	public Timeentry getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

	public List<Feedback> getFeedbacks() {
		return getInstance() == null ? null : new ArrayList<Feedback>(
				getInstance().getFeedbacks());
	}

}
